//
//  giftShowView.m
//  tcpoctest
//
//  Created by gump on 6/5/13.
//  Copyright (c) 2013 gump. All rights reserved.
//

#import "giftShowView.h"
#import "GiftInfoDataInfo.h"
#import "GiftInfoDataSource.h"

@implementation giftShowView

-(id)init
{
    self = [super init];
    
    if (self != nil) {
    }
    
    return self;
}

-(void)initUI
{
    UIView *toptapview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WINDOW_WIDTH, 100)];
    UITapGestureRecognizer *singleTouch = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                                  action:@selector(viewTap)];
    [self.view addSubview:toptapview];
    [toptapview addGestureRecognizer:singleTouch];
    
    UIView *bottomtapview = [[UIView alloc] initWithFrame:CGRectMake(0, 340, WINDOW_WIDTH, WINDOW_HIGTH - 340)];
    UITapGestureRecognizer *singleTouchbottom = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                                        action:@selector(viewTap)];
    [self.view addSubview:bottomtapview];
    [bottomtapview addGestureRecognizer:singleTouchbottom];
    
    UIImageView *bgview = [[UIImageView alloc] initWithFrame:CGRectMake(10, 100, 300, 240)];
    bgview.image = [UIImage imageNamed:@"gift_dialogbox_bg.png"];
    bgview.userInteractionEnabled = YES;
    [self.view addSubview:bgview];
    
   
    
    
    
    headimageview = [[UIImageView alloc] initWithFrame:CGRectMake(25, 80, 80, 80)];
    headimageview.image = [UIImage imageNamed:@"gift_default.png"];
    [bgview addSubview:headimageview];
    
    namelabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 52, 300, 20)];
    namelabel.textAlignment = UITextAlignmentCenter;
    namelabel.backgroundColor = [UIColor clearColor];
    namelabel.textColor = [UIColor whiteColor];
    [bgview addSubview:namelabel];
    
    warnlabel = [[UILabel alloc] initWithFrame:CGRectMake(110, 80, WINDOW_WIDTH - 110, 60)];
    warnlabel.textAlignment = UITextAlignmentCenter;
    warnlabel.backgroundColor = [UIColor clearColor];
    warnlabel.textColor = [UIColor whiteColor];
    warnlabel.numberOfLines = 0;
    [bgview addSubview:warnlabel];
    
}

-(void)viewTap
{
    
        [[ViewManager sharedViewManager] backViewDirect:self];
 
}

-(void)viewWillShow
{
    if (self.ginfo != nil) {
        if (self.ginfo.giftIsMusic == 2) {
            NSString *musicpath = [[DataControl shareControl].giftInfoDS
                                   GetMusicPathByID:self.ginfo.strgiftid];
            if (musicpath != nil && ![musicpath isEqualToString:@""]) {
                
                NSData *musicdata = [NSData dataWithContentsOfFile:musicpath];
                
                player=[[AVAudioPlayer alloc] initWithData:musicdata  error:nil];
                [player prepareToPlay];
                [player play];
            }
        }
    }
    
    [self refreshView];
}

-(void)refreshView
{
    if (self.ginfo != nil) {
        NSString *imagepath = [[DataControl shareControl].giftInfoDS
                               searchGiftImagePath:self.ginfo.strgiftid];
        
        if (imagepath != nil && ![imagepath isEqualToString:@""]) {
            headimageview.image = [UIImage imageWithContentsOfFile:imagepath];
        }
        
        namelabel.text = [NSString stringWithFormat:@"%@ x %d",
                          self.ginfo.strgiftname,
                          self.isendcount];
        
        int iprice = self.ginfo.giftprice / 10000;
        if (iprice > 0) {
            warnlabel.text = [NSString stringWithFormat:@"此礼物价值\n %d 万金币耶",
                              iprice];
        }
        else
        {
        
        warnlabel.text = [NSString stringWithFormat:@"此礼物价值\n %d 金币耶",
                          self.ginfo.giftprice];
        }
    }
}
@end
